# 定义问题及对应的选项得分
questions = [
    {
        "question": "当你参加社交活动时，你通常：",
        "options": [
            ("A. 很享受与人交流，结识新朋友", {"E": 1}),
            ("B. 更喜欢和熟悉的少数人待在一起", {"I": 1})
        ]
    },
    {
        "question": "做决策时，你更倾向于：",
        "options": [
            ("A. 基于逻辑和客观事实", {"T": 1}),
            ("B. 考虑他人的感受和人际关系", {"F": 1})
        ]
    },
    {
        "question": "面对新的计划或任务，你通常：",
        "options": [
            ("A. 提前做好详细的规划", {"J": 1}),
            ("B. 灵活应变，边做边调整", {"P": 1})
        ]
    },
    {
        "question": "获取信息时，你更注重：",
        "options": [
            ("A. 具体的事实和细节", {"S": 1}),
            ("B. 整体的概念和可能性", {"N": 1})
        ]
    }
]


def conduct_test():
    scores = {"E": 0, "I": 0, "S": 0, "N": 0, "T": 0, "F": 0, "J": 0, "P": 0}
    for i, question in enumerate(questions, start=1):
        print(f"问题 {i}: {question['question']}")
        for j, (option_text, option_score) in enumerate(question["options"], start=1):
            print(f"{j}. {option_text}")
        while True:
            try:
                choice = int(input("请输入你的选择（1 或 2）: "))
                if choice in [1, 2]:
                    for key, value in question["options"][choice - 1][1].items():
                        scores[key] += value
                    break
                else:
                    print("无效的选择，请输入 1 或 2。")
            except ValueError:
                print("输入无效，请输入一个数字。")
    return scores


def determine_mbti_type(scores):
    e_i = "E" if scores["E"] > scores["I"] else "I"
    s_n = "S" if scores["S"] > scores["N"] else "N"
    t_f = "T" if scores["T"] > scores["F"] else "F"
    j_p = "J" if scores["J"] > scores["P"] else "P"
    return f"{e_i}{s_n}{t_f}{j_p}"


def main():
    print("欢迎参加 MBTI 性格测试游戏！")
    scores = conduct_test()
    mbti_type = determine_mbti_type(scores)
    print(f"根据你的回答，你的 MBTI 性格类型是: {mbti_type}")


if __name__ == "__main__":
    main()